package org.aplombh.java.interview.newcoder;

import java.util.Scanner;

public class HJ33_整数与IP地址间的转换 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextLine()) {
            String ip = in.nextLine();
            if (ip.contains(".")) {
                System.out.println(toByte(ip));
            } else {
                System.out.println(toIpFormat(ip));
            }
        }
    }

    private static String toIpFormat(String ip) {
        long sum = Long.parseLong(ip);
        StringBuilder res = new StringBuilder();
        for (int i = 0; i < 4; i++) {
            long p = sum % 256;
            sum /= 256;
            res.insert(0, p + ".");
        }
        res.delete(res.length() - 1, res.length());
        return res.toString();
    }

    private static long toByte(String ip) {
        long sum = 0;
        String[] split = ip.split("\\.");
        for (String s : split) {
            sum *= 256;
            sum += Integer.parseInt(s);
        }
        return sum;
    }
}
